-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat($http): Added method to abort a pending request. (2nd attempt) #1836
Conversation
@Rick-KLN, there's an quick fick for that. Edit http.js (done method) to check if digest is already running. if(!$rootScope.$$phase) {
$rootScope.$apply();
} I forked it (https://github.com/The-Amazing-Society/angular.js/commit/623e12aea0a4fefa5d4225e72181b75bcec0dd5a) to implement this, had the same problem. |
Thanks guys. It looks like I incorrectly assumed that abort would fire the onreadystatechange event separately. I'll push a fix + test in a little bit here. |
@dbinit Great work, I borrowed code from you fork. I would be real nice to get this merged in. |
Thanks a lot guys! |
Will this ever get merged into a production release? |
+1 on the merge :) |
New $http specific method "abort" for promises. There are many cases where a long-running request might need to be interrupted, e.g. a view change. Implementation details: - after calling abort(), the promise is guaranteed to be resolved with a rejection (unless it has already been resolved) - abort() returns true if successfully aborted (or already aborted), or false if the abort failed because the promise was already resolved - has mock $httpBackend support Closes angular#1159
+1 |
+1 for merging this. Also looking forward to something similar for $resource. |
+1 |
👍 (Probably needs to be merged again). Okay, I was surprised at the lack of http's abort... so: What does this PR hold back? How we can help? |
How would you abort a pending request if you are using $resource? |
@damrbaby add a |
Unfortunately I don't think this is going to be accepted as is. There is still ongoing discussion as to what the best approach is. Using a $q progress callback might be more suitable (see #2223). If returning a rejection from a progress callback could abort the XHR, it would be almost equivalent to this. |
I did a bit more research and found several implementations of Deferred/Promise that have an optional "canceler" feature. I've submitted #2452 to implement that feature. If it's accepted, adding $http cancellation would be fairly trivial. |
+1, |
Fixes issue #1159. Was pull request #1623.
Addressed issues brought up by Miško: